// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Chopper Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 60 : TYPE_CHOPPER

// Function declarations
reserve function Chopper_DebugDraw
reserve function Chopper_DebugSpawn

// Static Values

// Tables

function Chopper_DebugDraw
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
end function


function Chopper_DebugSpawn
	CreateTempObject(TypeName[Chopper], 0, object.xpos, object.ypos)
	GetBit(temp0, object.direction, 0)
	object[tempObjectPos].direction = temp0
	object[tempObjectPos].value1 = object.ypos
	object[tempObjectPos].yvel = -0x70000
end function


event ObjectMain
	object.ypos += object.yvel
	object.yvel += 0x1800
	if object.yvel < -0x38000
		object.animation = 0
	else
		if object.yvel > 0x38000
			object.animation = 2
		else
			object.animation = 1
		end if
	end if
	if object.ypos > object.value1
		object.ypos = object.value1
		object.yvel = -0x70000
	end if
	CallFunction(PlayerObject_EnemyPop)
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -12, -14, 12, 14, currentPlayer, object[currentPlayer].value40, object[currentPlayer].value38, object[currentPlayer].value41, object[currentPlayer].value39)
		if checkResult == 1
			CallFunction(PlayerObject_BadnikBreak)
		end if
	next
	
	
	foreach (TypeName[Bullet], arrayPos0, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -12, -14, 12, 14, arrayPos0, -6, -4, 6, 4)
		if checkResult == 1
			CallFunction(BulletKill)
		end if
	next
	
	switch object.animation
	case 0
		object.frame = object.animationTimer
		object.frame >>= 3
		object.animationTimer++
		object.animationTimer &= 15
		break
	case 1
		object.frame = object.animationTimer
		object.frame >>= 3
		object.animationTimer += 2
		object.animationTimer &= 15
		break
	case 2
		object.frame = 0
		break
	end switch
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	CheckCurrentStageFolder("Zone01")
	if checkResult == 1
		LoadSpriteSheet("GHZ/Objects.gif")
		SpriteFrame(-14, -15, 30, 32, 98, 94)
		SpriteFrame(-14, -15, 30, 32, 129, 94)
	end if
	CheckCurrentStageFolder("BossRush")
	if checkResult == 1
		LoadSpriteSheet("MBZ/Objects.gif")
		SpriteFrame(-14, -15, 30, 32, 106, 81)
		SpriteFrame(-14, -15, 30, 32, 137, 81)
	end if
	CheckCurrentStageFolder("Zone00")
	if checkResult == 1
		LoadSpriteSheet("GHZ/Objects3.gif")
		SpriteFrame(-14, -15, 30, 32, 106, 81)
		SpriteFrame(-14, -15, 30, 32, 137, 81)
	end if
	foreach (TypeName[Chopper], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
		object[arrayPos0].yvel = -0x70000
	next
	SetTableValue(TypeName[Chopper], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Chopper_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Chopper_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
